#ifndef MSCENE_H
#define MSCENE_H
#include <QGraphicsSceneEvent>
#include <QGraphicsScene>
#include "mprocess.h"
#include "mtext.h"
#include "mDataManager.h"
#include "marrow.h"
#include <qdrag.h>
#include<Util/cstate.h>

QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
QT_END_NAMESPACE

class mScene : public QGraphicsScene
{
    Q_OBJECT

public:
    mScene(QObject *parent=0);
    ~mScene();

    enum Mode { InsertItem, InsertLine, InsertText, MoveItem };

    QFont font() const
    {return myFont;}
    QColor textColor() const
    { return myTextColor; }
    QColor itemColor() const
    { return myItemColor; }
    QColor lineColor() const
    { return myLineColor; }
    void setLineColor(const QColor &color);
    void setTextColor(const QColor &color);
    void setItemColor(const QColor &color);
    void setFont(const QFont &font);
    bool deleteItemFromData(int id); //从数据当中删除对象
    bool deleteArrowFromData(int id);
    bool saveDataToXMLFile(QString path);
    void initScene(qreal x, qreal y, QString text, QMap<QString, QHash<QString, QString> *> *Info);       //初始化scene上的模型显示
    void addAllInfo(QList<CState*> *DStateListMap);
    void addProcessItem(QMap<QString, QString> ActivityMap);
    void addProcessItem(QString UniqueID,QString StateName,qreal x,qreal y);
    void addArrowItem(QMap<QString ,QString> RuleMap);
    void addArrowItem(QString StartStateUniqueID, QString EndStateUniqueID);
    void getCurrent(int index);
public slots:
    void setMode(Mode mode);
    void editorLostFocus(mText *item);

signals:
    void itemInserted(mProcess *item);
    void textInserted(QGraphicsTextItem *item);
    void itemSelected(QGraphicsItem *item);
    void on_ModelState_doubleClicked(CState *);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);

private:
    bool isItemChange(int type);

    Mode myMode;
    bool leftButtonDown;
    QPointF startPoint;
    QGraphicsLineItem *line;
    QFont myFont;
    mText *textItem;
    QColor myTextColor;
    QColor myItemColor;
    QColor myLineColor;
    QColor myItemBorderLineColor;
    QColor myItemClickColor;
    QColor myItemDoubleClickColor;
    QList<CState *> *StateList;
    mDataManager *myDataManger;
    int currentIndex;
    QMap<QString,mProcess *> ProcessItemMap;
    mProcess * lastDoubleClickState=NULL;


};

#endif // MSCENE_H



